/*
 * @Author: xuhua
 * @Date: 2023-09-19 10:08:39
 * @LastEditors: xuhua
 * @LastEditTime: 2023-09-19 13:53:48
 * @FilePath: /v3-element-admin/mock/controller/user.ts
 * @Description:
 */
import type { MockMethod } from "vite-plugin-mock";
import Mock from "mockjs";
import { ResultEnum } from "../httpEnum";
const user: Array<MockMethod> = [
	{
		url: "/api/auth/login",
		method: "post",
		response: ({ body }) => {
			const { username, password } = body;
			// 判断用户名和密码是否正确
			if (username !== "admin" || password !== "123456") {
				return {
					code: 400,
					message: "用户名或密码错误",
					data: null,
				};
			}
			return {
				code: ResultEnum.SUCCESS,
				message: "登录成功",
				data: {
					accessToken:
						"eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiIsInVzZXJJZCI6MiwidXNlcm5hbWUiOiJhZG1pbiIsImRlcHRJZCI6MSwiZGF0YVNjb3BlIjoxLCJhdXRob3JpdGllcyI6WyJST0xFX0FETUlOIl0sImlhdCI6MTY5NTA4OTkwNSwiZXhwIjoxNjk1MDk3MTA1fQ.H2ABCmkQMyneUqueggO93e6lUuP25IKBybbPa-SZfI0",
					tokenType: "Bearer",
				},
			};
		},
	},
	{
		url: "/api/auth/logout",
		method: "delete",
		response: () => {
			return {
				code: 200,
				message: "退出成功",
				data: null,
			};
		},
	},
	{
		url: "/api/user/info",
		method: "get",
		response: () => {
			return {
				code: 200,
				message: "获取用户信息成功",
				data: {
					userId: Mock.mock("@id"),
					username: "admin",
					nickname: "系统管理员",
					avatar: "https://oss.youlai.tech/youlai-boot/2023/05/16/811270ef31f548af9cffc026dfc3777b.gif",
					roles: ["ADMIN"],
					perms: [
						"sys:menu:delete",
						"sys:dept:edit",
						"sys:dict_type:add",
						"sys:dict:edit",
						"sys:dict:delete",
						"sys:dict_type:edit",
						"sys:menu:add",
						"sys:user:add",
						"sys:role:edit",
						"sys:dept:delete",
						"sys:user:edit",
						"sys:user:delete",
						"sys:user:reset_pwd",
						"sys:dept:add",
						"sys:role:delete",
						"sys:dict_type:delete",
						"sys:menu:edit",
						"sys:dict:add",
						"sys:role:add",
					],
				},
			};
		},
	},
];

export default user;
